import AppConst from "../AppConst";
import LayerMgr from "../view/LayerMgr";
import TipView from "./TipView";


export default class TipMgr {
    private static _inst: TipMgr = null;
    public static get inst(): TipMgr { return this._inst || (this._inst = new TipMgr()); }

    private _tipPrefab: cc.Prefab = null;


    private constructor() {
        cc.loader.loadRes('mi/core/Tip', (err: Error, tipPrefab: cc.Prefab) => {
            if (!err) {
                this._tipPrefab = tipPrefab
            } else {
                cc.error('[mi]找不到Res[mi/core/Tip], err:', err);
            }
        });
    }


    public addTip(content: string): void {
        const panelTip = cc.instantiate(this._tipPrefab);
        LayerMgr.setLayer(panelTip, AppConst.viewLayer.Tip);

        const tipView = panelTip.addComponent(TipView);
        tipView.startTip(content);
    }
}
